package com.sangfor.ssl.service.netmonitor;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import com.sangfor.bugreport.logger.Log;
import com.sangfor.ssl.service.netmonitor.NetworkMonitor;
import java.util.HashSet;
import java.util.Set;

/* loaded from: classes2.dex */
public class NetworkMonitorReceiver extends BroadcastReceiver {
    private static final String TAG = "NetworkMonitorReceiver";
    private Set<NetworkMonitor.NetworkListener> mNetworkListenerList = new HashSet();
    private Set<NetworkMonitor.WiFiStateListener> mWiFiStateListenerList = new HashSet();

    /* JADX INFO: Access modifiers changed from: protected */
    public boolean registerNetworkMonitorListener(NetworkMonitor.NetworkListener networkListener) {
        boolean z;
        synchronized (this) {
            if (networkListener != null) {
                try {
                    z = this.mNetworkListenerList.add(networkListener) ? true : true;
                } finally {
                }
            }
            z = false;
        }
        return z;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public boolean unRegisterNetworkMonitorListener(NetworkMonitor.NetworkListener networkListener) {
        boolean z;
        synchronized (this) {
            if (networkListener != null) {
                try {
                    z = this.mNetworkListenerList.remove(networkListener) ? true : true;
                } finally {
                }
            }
            z = false;
        }
        return z;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public boolean registerWiFiStateListener(NetworkMonitor.WiFiStateListener wiFiStateListener) {
        boolean z;
        synchronized (this) {
            if (wiFiStateListener != null) {
                try {
                    z = this.mWiFiStateListenerList.add(wiFiStateListener) ? true : true;
                } finally {
                }
            }
            z = false;
        }
        return z;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public boolean unRegisterWiFiStateListener(NetworkMonitor.WiFiStateListener wiFiStateListener) {
        boolean z;
        synchronized (this) {
            if (wiFiStateListener != null) {
                try {
                    z = this.mWiFiStateListenerList.remove(wiFiStateListener) ? true : true;
                } finally {
                }
            }
            z = false;
        }
        return z;
    }

    @Override // android.content.BroadcastReceiver
    public void onReceive(Context context, Intent intent) {
        if (intent == null) {
            return;
        }
        if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) {
            boolean booleanExtra = intent.getBooleanExtra("noConnectivity", false);
            NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra("networkInfo");
            if (networkInfo == null) {
                return;
            }
            int type = networkInfo.getType();
            Log.info(TAG, "Connectivity changed: {" + networkInfo.getTypeName() + "[" + networkInfo.getSubtypeName() + "]:" + networkInfo.getState() + "/" + networkInfo.getDetailedState() + "}");
            if (type == 0) {
                String networkOperatorName = NetworkHelper.getNetworkOperatorName(context);
                String subtypeName = NetworkHelper.getSubtypeName(context);
                Log.info(TAG, "Current Network Info:[Mobile]" + networkOperatorName + "[" + subtypeName + "]");
                StringBuilder sb = new StringBuilder();
                sb.append("Network registers, size:");
                sb.append(this.mNetworkListenerList.size());
                sb.append(", ");
                sb.append(this.mNetworkListenerList.toString());
                Log.info(TAG, sb.toString());
                for (NetworkMonitor.NetworkListener networkListener : this.mNetworkListenerList) {
                    networkListener.onNetworkChanged(networkInfo, booleanExtra);
                }
            }
            if (1 == type) {
                String wiFiIPAddress = NetworkHelper.getWiFiIPAddress(context);
                String gatewayIP = NetworkHelper.getGatewayIP(context);
                Log.info(TAG, "Current Network Info:[WiFi]" + NetworkHelper.getWiFiSSID(context) + "[ip:" + wiFiIPAddress + "gateway: " + gatewayIP + "]");
                StringBuilder sb2 = new StringBuilder();
                sb2.append("Network registers, size:");
                sb2.append(this.mNetworkListenerList.size());
                sb2.append(", ");
                sb2.append(this.mNetworkListenerList.toString());
                Log.info(TAG, sb2.toString());
                for (NetworkMonitor.NetworkListener networkListener2 : this.mNetworkListenerList) {
                    networkListener2.onNetworkChanged(networkInfo, booleanExtra);
                }
            }
        } else if ("android.net.wifi.WIFI_STATE_CHANGED".equals(intent.getAction())) {
            int intExtra = intent.getIntExtra("previous_wifi_state", 4);
            int intExtra2 = intent.getIntExtra("wifi_state", 4);
            for (NetworkMonitor.WiFiStateListener wiFiStateListener : this.mWiFiStateListenerList) {
                wiFiStateListener.onWiFiChanged(intExtra2, intExtra);
            }
        }
    }
}
